import { v3 } from 'cc';
import { view } from 'cc';
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

/**
 * 适配屏幕高度的情况下适用，
 * 宽度会变化，窄于设计分辨率时通过scale压缩节点大小
 */

@ccclass('ScaleWidthToVisibleSize')
export class ScaleWidthToVisibleSize extends Component {

    callback: () => void = null;

    onLoad() {
        const visibleSize = view.getVisibleSize();
        const designSize = view.getDesignResolutionSize();
        if (visibleSize.width < designSize.width) {
            const scale = visibleSize.width / designSize.width;
            this.node.setWorldScale(v3(scale, scale, scale));
        }
        this.callback && this.callback();
    }

}


